package webapp.frontOffice.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import modele.contrat.Action;
import modele.contrat.OptionC;
import modele.utilisateur.Utilisateur;
import dao.contrat.ActionDAO;
import dao.contrat.OptionCDAO;

/**
 * Servlet implementation class MesActions
 */
@WebServlet("/mesactions")
public class MesActions extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		HttpSession session = request.getSession();
		
		if(session == null || session.getAttribute("type") == null || !session.getAttribute("type").equals("investisseur"))
		{
			response.sendRedirect("index.jsp");
		}
		else
		{
			Utilisateur user = (Utilisateur)session.getAttribute("user");
			List<Action> actions = new ActionDAO().retrieveByProprietaire(user);
			List<OptionC> options = new OptionCDAO().retrieveByProprietaire(user);
			request.setAttribute("actions", actions);
			request.setAttribute("options", options);
			
	        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/viewFrontoffice/actionMaListe.jsp");
	        dispatcher.forward(request, response);
		}
	}


}
